package com.heima.xianchengchi;

import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class MyExecutor03 {
    public static void main(String[] args) {
        //submit作为返回值接受参数，--Future<>
        ExecutorService executorService = Executors.newCachedThreadPool();
        ArrayList<Future<String>> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            int c = i;
            Future<String> submit = executorService.submit(() -> {
                System.out.println(Thread.currentThread().getName() + c);
                return "Thread" + c;
            });
            list.add(submit);
        }
        for (Future<String> stringFuture : list) {
            try {
                System.out.println(stringFuture.get());
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
    }
}